package com.ylsf.blog.controller;

import com.alibaba.fastjson.JSON;
import com.ylsf.blog.pojo.ArticleComment;
import com.ylsf.blog.service.SquareService;
import com.ylsf.blog.service.impl.SquareServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 博客广场控制类
 */
@WebServlet("/square")
public class SquareServlet extends HttpServlet {
    private SquareService squareService=new SquareServiceImpl();
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        List<ArticleComment> articleComments = squareService.listAllArticleComments();
        //System.out.println(articleComments);
        String jsonString = JSON.toJSONString(articleComments);
        response.getWriter().print(jsonString);
    }
}
